<?php
class ModelModuleTopMenu extends Models
{
    protected $tableName='top_menu_layouts';

    public function getLink($route='')
    {
        $this->load->model('design/layout');
        return $this->model_design_layout->getLink($route);
    }

    public function getActiveLink($links)
    {
        if($this->config->get('config_seo_url')){
            $route=$this->request->server['REQUEST_URI'];

            if(strpos($route, 'route=')){
                $route='/'.$this->request->get['route'];
            }

            if(strpos($route, 'art=') || strpos($route, 'vendor=')){
                $tmpArr=explode('?', $route);
                if($tmpArr) $route=$tmpArr[0];
            }

            if($route=='/index.php') $route='/';

            foreach($links as $num=>$link){
                $tmpArr=explode('/', $link['url']);
                $url='/'.end($tmpArr);
                if($url==$route) $links[$num]['class'].=' active';
            }
        }else{
            $routeId=isset($this->request->get['information_id']) ? (int)$this->request->get['information_id'] : '';

            $links[0]['class'].=' active';

            if($routeId){
                foreach($links as $num=>$link){
                    $id=(int)substr($link['url'], strlen($link['url'])-1, 1);
                    if(!$id) $id=(int)substr($link['url'], strlen($link['url'])-2, 2);
                    if($id==$routeId) $links[$num]['class'].=' active';
                }
            }
        }

        $this->load->helper('html');
        $result='';
        if($links){
            foreach($links as $num=>$link){
                $result.=getUrl(array(
                    'href'=>$link['url'],
                    'text'=>$link['name'],
                    'container'=>'td',
                    'container_class'=>'button '.$link['class'],
                    'link_class'=>'text-decoration-none white-color',
                    'data_url'=>$link['url'],
                ));
            }
        }

        return $result;
    }
}